//---------------------------------------------------------------------------

#ifndef CEICDatabaseH
#define CEICDatabaseH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <dbtables.hpp>
#include <db.hpp>
#include <ibdatabase.hpp>
//---------------------------------------------------------------------------
class CEICDatabase;
typedef void __fastcall (__closure *CEICDatabaseLoginEvent)(CEICDatabase* Database, Classes::TStrings* LoginParams);

class PACKAGE CEICDatabase : public TComponent
{
private:
  TDatabase*             FDatabase;
  TIBDatabase*           FIBDatabase;
  bool                   FBDEstInterbase;
  CEICDatabaseLoginEvent FOnLogin;

  //Variables temporaires pour pré-initialisation avant création du TDatabase ou du TIBDatabase
    //des Propriétés Published
      AnsiString         FAliasName_Tmp;
      AnsiString         FDatabaseName_Tmp;
      bool               FLoginPrompt_Tmp;
      Classes::TStrings* FParams_Tmp;
      AnsiString         FSessionName_Tmp;
    //des Evènements
      Classes::TNotifyEvent FAfterConnect_Tmp;
      Classes::TNotifyEvent FAfterDisconnect_Tmp;
      Classes::TNotifyEvent FBeforeConnect_Tmp;
      Classes::TNotifyEvent FBeforeDisconnect_Tmp;

  AnsiString             __fastcall GetAliasName(void);
  void                   __fastcall SetAliasName(const AnsiString Value);
  Classes::TStrings*     __fastcall GetDBParams(void);
  void                   __fastcall SetDBParams(Classes::TStrings* Value);
  AnsiString             __fastcall GetSessionName(void);
  void                   __fastcall SetSessionName(const AnsiString Value);

  TNotifyEvent           __fastcall GetAfterConnect(void);
  void                   __fastcall SetAfterConnect(const TNotifyEvent Value);
  TNotifyEvent           __fastcall GetAfterDisconnect(void);
  void                   __fastcall SetAfterDisconnect(const TNotifyEvent Value);
  TNotifyEvent           __fastcall GetBeforeConnect(void);
  void                   __fastcall SetBeforeConnect(const TNotifyEvent Value);
  TNotifyEvent           __fastcall GetBeforeDisconnect(void);
  void                   __fastcall SetBeforeDisconnect(const TNotifyEvent Value);
  void                   __fastcall DbLoginEvent(  TDatabase*   Database, Classes::TStrings* LoginParams);
  void                   __fastcall IBDbLoginEvent(TIBDatabase* Database, Classes::TStrings* LoginParams);

protected:
  virtual bool       __fastcall GetConnected(void);
  virtual void       __fastcall SetConnected(bool Value);
          AnsiString __fastcall GetDatabaseName(void);
          void       __fastcall SetDatabaseName(const AnsiString Value);
          bool       __fastcall GetLoginPrompt(void);
          void       __fastcall SetLoginPrompt(bool Value);

public:
  virtual __fastcall ~CEICDatabase();
  __fastcall CEICDatabase(TComponent* Owner);

  __property TDatabase*   BDEDataBase    = {read=FDatabase,       write=FDatabase};
  __property TIBDatabase* IBDataBase     = {read=FIBDatabase,     write=FIBDatabase};

  void __fastcall Close(void);
  void __fastcall CloseDataSets(void);
  void __fastcall Open(void);

__published:
  //Propriétés Published
  __property AnsiString         AliasName      = {read=GetAliasName,    write=SetAliasName};
  __property bool               BDEstInterbase = {read=FBDEstInterbase, write=FBDEstInterbase, default=false};
  __property bool               Connected      = {read=GetConnected,    write=SetConnected,    default=0};
  __property AnsiString         DatabaseName   = {read=GetDatabaseName, write=SetDatabaseName};
  __property bool               LoginPrompt    = {read=GetLoginPrompt,  write=SetLoginPrompt,  default=0};
  __property Classes::TStrings* Params         = {read=GetDBParams,     write=SetDBParams};
  __property AnsiString         SessionName    = {read=GetSessionName,  write=SetSessionName};
  //Evènements
  __property Classes::TNotifyEvent  AfterConnect     = {read=GetAfterConnect,     write=SetAfterConnect};
	__property Classes::TNotifyEvent  AfterDisconnect  = {read=GetAfterDisconnect,  write=SetAfterDisconnect};
  __property Classes::TNotifyEvent  BeforeConnect    = {read=GetBeforeConnect,    write=SetBeforeConnect};
	__property Classes::TNotifyEvent  BeforeDisconnect = {read=GetBeforeDisconnect, write=SetBeforeDisconnect};
  __property CEICDatabaseLoginEvent OnLogin          = {read=FOnLogin,            write=FOnLogin};
};
//---------------------------------------------------------------------------
#endif
 